/*
 * @Author       : Deusit && 505097558@qq.com
 * @Date         : 2023-06-05 23:02:55
 * @LastEditors  : Deusit && 505097558@qq.com
 * @LastEditTime : 2023-08-02 02:28:10
 * @Description  : file content
 * @FilePath     : deusitWifi.h
 * Copyright (c) 2023 by Deusit email: 505097558@qq.com, All Rights Reserved.
 */

#ifndef _DEUSITWIFI_H_
#define _DEUSITWIFI_H_
#ifdef ARDUINO
#include <Arduino.h>
#endif
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <PubSubClient.h>
#include <Ticker.h>


class DEUSIT_WIFI
{
    public:
        DEUSIT_WIFI(const char* deviceName = "Deusit_ESP8266", const char* hostName = "Deusit_ESP8266", const char* APName = "Deusit_WIFI");
        ~DEUSIT_WIFI(){
            //this->mqttTimer.detach();
        }
        void begin();
        void deviceInfo(bool returnJson);
        String readConfig(String);
        void writeConfig(String, std::variant<String, int, float>);
        static void mqttSub(char* topic, byte* payload, unsigned int length);
        void mqttPub();
    private:
        const char* deusitWifiVersion = "1.0.0";
        static const char* deviceName;
        static const char* hostName;
        static const char* APName;
        Ticker mqttTimer;
        WiFiClient espClient;
        PubSubClient mqttClient;
        
        void wifiInit();
        static void wifiHeart(DEUSIT_WIFI* instance);
        String getContentType(String filename);
        void handleFileRead(String path);
        void wwwroot();
        String wifi_type(int typecode);
        void wifiScan();
        void wifiConfig();
        void wifiAuto();
        static void wifiReset();
        void mqttAuto();
        void mqttRefresh();
        void mqttSubmit();
        void opera();
};
#endif